//
//  LBBall.m
//  LittleBall
//
//  Created by apple on 11-11-27.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import "LBBall.h"

@implementation LBBall

@synthesize m_imageView;
@synthesize m_bSelected;
@synthesize m_row;
@synthesize m_column;
@synthesize m_color;


-(id)initWithImage:(UIImage *)image atRow:(int)row atColumn:(int)column withColor:(BALL_COLOR)color
{
    if( !(self = [super init]))
    {
        return nil;
    }
    
    if (m_imageView) 
    {
        NSLog(@"LBBall::initWithImage() | m_imageView is not NULL, just setImage!");
        
        [m_imageView setImage:image];
    }
    else
    {
        m_imageView = [[UIImageView alloc] initWithImage: image];
        m_imageView.center = [LBPathFinder translatePositionToCenterPointFromRow:row column:column];
    }
    
    m_row = row;
    m_column = column;
    m_color = color;
    
    return self;
}

-(BOOL)ifTheBallIsAtRow:(int)row atColumn:(int)column
{
    if (row == m_row && column == m_column)
    {
        return TRUE;
    }
    
    return FALSE;
}

-(BOOL)ifTheBallIsThisView:(UIView*)view
{
    if( view == m_imageView )
    {
        return TRUE;
    }
    return FALSE;
}

-(BOOL)ifTheBallCoverThePoint:(CGPoint)point
{
    if (m_imageView.center.x - BALL_WIDTH/2 < point.x
        && m_imageView.center.x + BALL_WIDTH/2 > point.x
        && m_imageView.center.y - BALL_HEIGHT/2 < point.y
        && m_imageView.center.y + BALL_HEIGHT/2 > point.y ) 
    {
        return TRUE;
    }
    
    return FALSE;
}

@end